#ifndef _TRIANGLE_H_
#define _TRIANGLE_H_

#include <list>
#include <glm/glm.hpp>
#include "ray.h"


class Triangle {
public:
	typedef std::list<Triangle*> List;
	typedef List::iterator Iter;
	typedef List::const_iterator cIter;

	Triangle(const glm::vec3& v1,
			 const glm::vec3& v2,
			 const glm::vec3& v3,
			 const glm::vec3& col);

	// Compute normal
	void computeNormal();

	void scale(float factor);
	void move(const glm::vec3& relPos);
	void mirrorX();
	void mirrorY();

	// Find the 3D intersection of a ray with a triangle
	// using Möller–Trumbore intersection algorithm.
	// Output: distance from ray start to intersection.
	// Return false if ray does not intersect.
	bool rayIntersect(const Ray& ray, float* distance) const;

	const glm::vec3& getNormal() const {
		return _normal;
	}
	const glm::vec3& getColor() const {
		return _color;
	}
	const glm::vec3* getVertices() const {
		return _vertices;
	}

private:
	glm::vec3 _vertices[3];
	glm::vec3 _normal;
	glm::vec3 _color;
};

#endif // _TRIANGLE_H_

